// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
import App from './App'
import router from './router'
import store from './store'
import './assets/css/reset.css'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueCookie from 'vue-cookie'
import VeeValidate from 'vee-validate';
import moment from 'moment'

Vue.use(Vuex)
Vue.use(ElementUI);
Vue.use(VueCookie);
/**
 * 拦截器
 */
axios.defaults.retry = 3;
axios.defaults.retryDelay = 5000;
let bol = true
// axios.defaults.headers.common['Content'] = 'application/x-www-form-urlencoded'
axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
 var config = err.config;
 if(!config || !config.retry) return Promise.reject(err);
 config.__retryCount = config.__retryCount || 0;
 if(config.__retryCount >= config.retry) {
  if(bol) {
    Vue.prototype.$alert("服务器连接中断,请刷新后重试!");
    bol = false
  }
  setTimeout( res => {
    bol = true
  },4000)
  return Promise.reject(err);
 }
 config.__retryCount += 1;
 var backoff = new Promise(function(resolve) {
  setTimeout(function() {
   resolve();
  }, config.retryDelay || 1);
 });
 return backoff.then(function() {
   
  return axios(config);
 });
});

Vue.config.productionTip = false
Vue.prototype.$ajax = axios
Vue.prototype.$moment = moment;

// Vue.use(axios)


const VeeValidateConfig = {
  aria: true,
  classNames: {},
  classes: false,
  delay: 0,
  dictionary: null,
  errorBagName: 'errors', // change if property conflicts
  events: 'input|blur',
  fieldsBagName: 'fields',
  i18n: null, // the vue-i18n plugin instance
  i18nRootKey: 'validations', // the nested key under which the validation messages will be located
  inject: true,
  locale: 'cn',
  validity: false
}
Vue.use(VeeValidate, VeeValidateConfig)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
